import request from '@/utils/request'

// 收文表 VO
export interface ReceiveArticleVO {
	id: number // 主键Id
	title: string // 标题
	mainText: string // 正文
	receiptDate: Date // 收文时间
	receiptDocNumber: string // 收文单号
	reason: string // 事由
	deptHeadInstructions: string // 部门负责人拟办和批示
	dividingLeaderInstructions: string // 分管领导拟办和批示
	departmentResponsible: string // 部室承办
	remark: string // 备注
	isPublic: number // 是否公开 0不公开 1公开
	[key: string]: any
}

// 收文表 API
export const ReceiveArticleApi = {
	// 查询收文表分页
	getReceiveArticlePage: async (params: any) => {
		return await request.get({ url: `/system/receive-article/page`, params })
	},

	// 查询收文表详情
	getReceiveArticle: async (id: number) => {
		return await request.get({ url: `/system/receive-article/get?id=` + id })
	},

	// 新增收文表
	createReceiveArticle: async (data: ReceiveArticleVO) => {
		return await request.post({ url: `/system/receive-article/create`, data })
	},

	// 修改收文表
	updateReceiveArticle: async (data: ReceiveArticleVO) => {
		return await request.put({ url: `/system/receive-article/update`, data })
	},

	//年份历史History
	getInComingHistoryByYear: async (params: any) => {
		return await request.get({ url: '/bpm/receive-processing/get-list-by-year', params })
	},

	// 删除收文表
	deleteReceiveArticle: async (id: number) => {
		return await request.delete({ url: `/system/receive-article/delete?id=` + id })
	},

	// 导出收文表 Excel
	exportReceiveArticle: async (params: any) => {
		return await request.download({ url: `/system/receive-article/export-excel`, params })
	},
}

// 收文处理专用筏
export interface ReceiveArticleHandleVO {
	id: number; // 主键Id
	processInstanceId: number,
	raId: number; // 收文表Id
	documentNumber: string; // 编号
	fromAgency: string; // 来文机关
	documentCode: string; // 来文文号
	secretLevel: undefined, // 密级程度
	subject: string; // 事由
	receptionTime: string | number; // 收文时间
	type: number; // 收文类型 0拟办 1批示
	remark: string; // 备注
	isRead: boolean; // 阅读状态 0未读 1已读
	status: number
	isApproved: any
	startUserSelectAssignees: any
	eids: any
	ename: any
	[key: string]: any
}

export const ReceiveArticleHandlApi = {
	// 查询收文处理专用筏分页
	getReceiveArticleHandlePage: async (params: any) => {
		return await request.get({ url: `/bpm/receive-processing/page`, params })
	},

	// 查询收文处理专用筏详情
	getReceiveArticleHandle: async (id: number) => {
		return await request.get({ url: `/bpm/receive-processing/get?id=` + id })
	},

	// 新增收文处理专用筏
	createReceiveArticleHandle: async (data: ReceiveArticleHandleVO) => {
		return await request.post({ url: `/bpm/receive-processing/create`, data })
	},

	// 修改收文处理专用筏
	updateReceiveArticleHandle: async (data: ReceiveArticleHandleVO) => {
		return await request.put({ url: `/bpm/receive-processing/update`, data })
	},
	//年份历史History
	getInComingHistoryByYear: async (params: any) => {
		return await request.get({ url: '/bpm/receive-processing/get-list-by-year', params })
	},
	// 删除收文处理专用筏
	deleteReceiveArticleHandle: async (id: number) => {
		return await request.delete({ url: `/bpm/receive-processing/delete?id=` + id })
	},
	//年份历史History
	getInComingYear: async () => {
		return await request.get({ url: '/bpm/receive-processing/get-history-list' })
	},
	
}

// 抄送 VO
export interface CopyArticleVO {
	creator: number[] // 抄送人
	taskId: number // 任务编号
}

export const CarBonApi = {
	// 新增抄送
	createCopyArticle: async (data: CopyArticleVO) => {
		return await request.post({ url: `/bpm/process-instance/copy/create`, data })
	},
	// 查询抄送分页
	getCopyArticlePage: async (params: any) => {
		return await request.get({ url: `/bpm/process-instance/copy/receive-page`, params })
	},

	// 查询抄送详情
	getCopyArticle: async (id: number) => {
		return await request.get({ url: `/system/carbon-copy/get?id=` + id })
	},

	// 查询我发起的抄送分页
	getMyCopyArticlePage: async (params: any) => {
		return await request.get({ url: `/bpm/process-instance/copy/sent-page`, params })
	},

	// 已读抄送
	markCopyArticleRead: async (id: any) => {
		// 检查id是否为数组或逗号分隔的字符串
		let params = '';
		if (Array.isArray(id)) {
			// 如果是数组，直接处理
			params = id.map(item => `id=${item}`).join('&');
		} else if (typeof id === 'string' && id.includes(',')) {
			// 如果是逗号分隔的字符串，先分割后处理
			params = id.split(',').map(item => `id=${encodeURIComponent(item.trim())}`).join('&');
		} else {
			// 单个id的情况
			params = `id=${encodeURIComponent(id)}`;
		}

		return await request.put({ url: `/bpm/process-instance/copy/read?${params}` });
	}
}


// 推送 VO
export interface PushArticleVO {
	creator: number[] // 推送人
	taskId: number // 任务编号
	description: string // 描述
}

export const PushArticleApi = {
	// 新增推送
	createPushArticle: async (data: PushArticleVO) => {
		return await request.post({ url: `/bpm/process-instance/copy/create-push`, data })
	},

	// 查询推送分页
	getPushArticlePage: async (params: any) => {
		return await request.get({ url: `/bpm/process-instance/copy/push-page`, params })
	},

	// 查询我发起的推送
	getMyPushArticlePage: async (params: any) => {
		return await request.get({ url: `/bpm/process-instance/copy/sent-push-page`, params })
	},
}